import Vue from 'vue'
import Router from 'vue-router'
import login from "../views/login/login";
import index from '../views/index/index'
import MapView from "../views/index/IndexMapView";
// import singerDetail from "../views/music/singerDetail/singerDetail";
//路由懒加载
const recommend = () => import('../views/music/discover/discoverItem/recommend')
const MusicListDetail = () => import('../views/music/musicListDetail/musicListDetail')
const search = () => import('../views/music/search/search')
const album = () => import("../views/music/album/album")
const searchSongs = () => import('../views/music/search/searchItem/SearchSong')
const searchMusicList = () => import("../views/music/search/searchItem/searchMusicList")
const searchSinger = () => import("../views/music/search/searchItem/searchSinger")
const SingerDetail = () => import("../views/music/singerDetail/singerDetail")
const searchAlbum = () => import("../views/music/search/searchItem/searchAlbum")
const searchVideo = () => import("../views/music/search/searchItem/searchVideo")
const VideoDetail = () => import('../views/music/videoDetail/videoDetail')
const VideoIndex = () => import('../views/music/video/VideoIndex')
const VideoList = () => import("../views/music/video/VideoItem/VideoList")
const favoritesIndex = () => import('../views/music/favorites/favoritesIndex')
const favoritesAlbum = () => import('../views/music/favorites/favoritesItem/favoritesAlbum')
const favoritesSinger = () => import('../views/music/favorites/favoritesItem/favoritesSinger')
const favoritesVideo = () => import('../views/music/favorites/favoritesItem/favoritesVideo')
const recommendMusic = () => import('../views/music/recommendMusic/recommendMusic')
const musicListIndex = () => import('../views/music/discover/discoverItem/musicListIndex')
const musicList = () => import('../views/music/discover/discoverItem/musicListItem/musicList')
const musicListHighQuality = () => import('../views/music/discover/discoverItem/musicListItem/MusicListHighquality')
const musicSinger = () => import('../views/music/discover/discoverItem/musicSinger')
const musicRanking = () => import('../views/music/discover/discoverItem/musicRanking')
const Personal = () => import('../views/music/personal/personal-index')
const Followed = () => import('../views/music/personal/pesonal-children/followed')
const personal_fans = () => import('../views/music/personal/pesonal-children/personal-fans')
//const userList = () => import('../views/userList/userList')
Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new Router({
  mode: 'hash',
  routes: [
 
    {
      path: '/physical_exam/res',
      redirect: '/physical_exam/res/base',
      component: () => import('../views/physical/physica-res-form/index.vue'),
      children:[
        {
          path: '/physical_exam/res/base',
          component: () => import('../views/physical/physica-res-form/baseinfo.vue')
        },
        {
          path: '/physical_exam/res/bloodcheck',
          component: () => import('../views/physical/physica-res-form/bloodcheck.vue')
        },
        {
          path: '/physical_exam/res/immunoassay',
          component: () => import('../views/physical/physica-res-form/immunoassay.vue')
        },
        {
          path: '/physical_exam/res/ultrasound',
          component: () => import('../views/physical/physica-res-form/ultrasound.vue')
        },
        {
          path: '/physical_exam/res/xray',
          component: () => import('../views/physical/physica-res-form/xray.vue')
        },
        {
          path: '/physical_exam/res/ecg',
          component: () => import('../views/physical/physica-res-form/ecg.vue')
        },
      ]
    },
    {path:"/physical/notice",name:"/physical/notice",component:()=>import('../views/physical/notice/notice')},
    {path: '/', redirect: '/login'},
    {path: '/login', name: 'login', component: login},
    {path: '/MapView', name: 'MapView', component: MapView},
    {
      path: '/index', name: 'index', component: index,
      children: [
        {path: '/userList', component: () => import('../views/physical/userList/userList')},
        //  路由懒加载
        {
          path: '/upload_physical_exam',
          component: () => import('../views/physical/upload_physical_exam/upload_physical_exam')
        },
        {
          path: '/self_info',
          component: () => import('../views/physical/self_info/self_info')
        },
        {
          path: '/info/information',
          component: () => import('../views/physical/information/information')
        },
        {
          path: '/media/music', component: () => import('../views/music/main/index'),
          redirect: '/music/discover',
          children: [
            {
              path: '/music/discover', name: 'discover', component: () => import('../views/music/discover/discover'),
              redirect: '/discover/recommend',
              children: [
                {path: '/discover/recommend', component: recommend},
                {
                  path: '/discover/musicListIndex', component: musicListIndex,
                  redirect: '/discover/musicListIndex/musicList',
                  children: [
                    {path: '/discover/musicListIndex/musicList', component: musicList},
                    {path: '/discover/musicListIndex/musicListHighQuality', component: musicListHighQuality},
                  ]
                },
                {path: '/discover/singer', component: musicSinger},
                {path: '/discover/ranking', component: musicRanking},

              ]

            },
            //我的视频
            {
              path: '/music/videoIndex', name: "videoIndex", component: VideoIndex,
              redirect: '/video/videolist',
              children: [
                {path: '/video/videolist', name: "videolist", component: VideoList},
              ]
            },
            //我的收藏
            {
              path: '/music/favorites', name: "favoritesIndex", component: favoritesIndex,
              redirect: '/favorites/favoriteAlbum',
              children: [
                {path: '/favorites/favoriteAlbum', name: "favoriteAlbum", component: favoritesAlbum},
              ]
            },
            //每日推荐
            {path: '/music/recommend', name: "recommend", component: recommendMusic},
            {path: 'music/personal-index/:uid', name: 'music/personal-index', component: Personal},
            {path: '/musiclistdetail/:id', name: 'musicListDetail', component: MusicListDetail},
            {path: '/album/:id', name: 'album', component: album},
            {path: '/singerDetail/:id', name: 'singerDetail', component: SingerDetail},
            {path: '/videoDetail/:id/:type', name: 'videoDetail', component: VideoDetail},
            {path: 'music/personal-index/followed/:uid', name: 'music/personal-index/followed', component: Followed},
            {
              path: 'music/personal-index/personal-fans/:uid',
              name: 'music/personal-index/personal-fans',
              component: personal_fans
            },

            //  搜索歌曲
            {
              path: '/search/:id', name: 'search', component: search, redirect: '/search/search-songs/:id',
              children: [
                //搜索歌曲
                {path: '/search/search-songs/:id', component: searchSongs},
                //歌单
                {path: "/search/search-music-list/:id", component: searchMusicList},
                //  歌手
                {path: "/search/search-singers/:id", component: searchSinger},
                //专辑
                {path: "/search/search-album/:id", component: searchAlbum},
                //   视频
                {path: "/search/search-video/:id", component: searchVideo}
              ]
            }

          ]
        },
        //  路由懒加载
        {path: '/userauth', component: () => import('../views/index/auth')},
        {
          // path: '/blogs/blogsOnline', component: () => import('../views/blog/BlogIndex'),
          path: '/blogs/blogsOnline',
          //必须先显示BlogIndex，才能重定向到文章list，否则不会显示list内容
          component: () => import('../views/blog/BlogIndex'),
          redirect: '/list',
          children: [
            {
              path: '/list',
              name: 'list',
              component: () => import('../views/blog/list')
            },
            {
              path: '/articel/:id',
              name: 'articel',
              component: () => import('../views/blog/article'),
            }
          ]
        },
      ]
    },

  ]
})
//路由导航守卫
// 挂载路由导航守卫,to表示将要访问的路径，from表示从哪里来，
// next是下一个要做的操作 next('/login')强制跳转login
router.beforeEach((to, form, next) => {
  // console.log(to.path)
  // 访问登录页，放行
  if (to.path === '/login') {
    next()
  } else {
    // 获取token
    const token = window.sessionStorage.getItem('token');
    // 没有token, 强制跳转到登录页
    if (!token) {
      next('/login')
    } else {
      next()
    }
  }
})
export default router
